package com.lianniu.web.sellerOrder.action;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.baseService.user.model.Supply;
import com.lianniu.web.baseService.user.service.ISupplyService;
import com.lianniu.web.sellerOrder.service.ISellerOrderService;
import com.lianniu.web.sellerOrder.vo.CancelOrder;
import com.lianniu.web.sellerOrder.vo.OrderInfoVo;
import com.lianniu.web.sellerOrder.vo.SellerOrderConditionVo;
import com.lianniu.web.sellerOrder.vo.ShipmentVo;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/rest/sellerOrder")
public class SellerOrderRestAction {

  @Autowired
  ISellerOrderService sellerOrderService;
  @Autowired
  ISupplyService sellerService;
  @RequestMapping("/getOrderInfo")
  public @ResponseBody BaseResult getOrderInfo(String orderid){
    
    BaseResult result = sellerOrderService.getOrderInfo(orderid);
    return result;
  }
  @RequestMapping("/getOrders")
  public @ResponseBody BaseResult getOrders(SellerOrderConditionVo condition){
    BaseResult result = sellerOrderService.getOrders(condition);
   
    return result;
  }
  
  @RequestMapping("/cancelOrder")
  public @ResponseBody BaseResult cancelOrder(CancelOrder cancel){
    BaseResult result = sellerOrderService.cancelOrder(cancel);
    return result;
  }
  
  @RequestMapping("/shipmentData")
  public @ResponseBody BaseResult shipmentData(String userid,String orderid,ModelMap map){
    OrderInfoVo order =(OrderInfoVo) sellerOrderService.getOrderInfo(orderid).getData();
    Supply seller = (Supply)sellerService.selectByUsersId(userid).getData();
    
    map.put("seller", seller);
    map.put("order", order);
    
    return BaseResult.success(map);
  }
  
  @RequestMapping("/shipment")
  public @ResponseBody BaseResult shipment(ShipmentVo shipment){
    
    return sellerOrderService.shipment(shipment);
  }

  @RequestMapping("/trend")
  public @ResponseBody BaseResult trend(HttpServletRequest req){
    String pageNow = req.getParameter("pageNum");
    if(StringUtils.isBlank(pageNow)){
      pageNow = "0";
    }
    int pageNum = Integer.valueOf(pageNow);
    return sellerOrderService.getTrend(pageNum);
  }
}
